package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Room;
import cn.wolfcode.trip.base.query.RoomQuery;
import cn.wolfcode.trip.base.service.IHotelService;
import cn.wolfcode.trip.base.service.IRoomService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("rooms")
public class RoomController {
    @Autowired
    private IRoomService roomService;
    @Autowired
    private IHotelService hotelService;

    /**
     * 全部房间
     * @param
     * @return
     */
    @GetMapping("/{hotelId}")
    public Object list(RoomQuery qo){
        PageInfo pageInfo = roomService.queryForList(qo);
        return pageInfo;
    }
    /*@GetMapping("/hotel/{hotelId}")
    public Object hotel(@PathVariable Long hotelId){
        PageInfo pageInfo = roomService.queryForList(hotelId);
        return pageInfo;
    }*/

    /**
     * 根据roomID 获取对象
     * @param roomId
     * @return
     */
    @GetMapping("/pay/{roomId}")
    public Object list(@PathVariable Long roomId){
        Room room = roomService.queryByRoomId(roomId);
        return room;
    }

    /**
     * 酒店
     * @param qo
     * @return
     */
    @GetMapping("/commends")
    public Object commends(RoomQuery qo){
        //qo.setOrderBy("t.releaseTime desc");
        qo.setState(1);//推荐的酒店
        PageInfo pageInfo = roomService.queryForList(qo);
        return pageInfo;
    }
    @PutMapping
    public Object updata(Room room){
        JSONResult jsonResult = new JSONResult();
        try {
            roomService.saveOrUpdate(room);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark(e.getMessage());
        }
        return jsonResult;
    }

}
